class FinancialAccount < ActiveRecord::Base include AccountNumber belongs_to :organization belongs_to :financial_account_type has_many :case_type_account_numbers has_many :service_type_account_numbers, class_name: "ClientServiceTypeAccountNumber" attr_accessible :id, :number, :name, :description, :financial_account_type_id, :organization_id, :account_number_source, :case_type_account_numbers_attributes, :service_type_account_numbers_attributes accepts_nested_attributes_for :case_type_account_numbers, :service_type_account_numbers validates_presence_of :name, :financial_account_type_id validates_uniqueness_of :name, scope: :organization_id def account_number number end def account_type financial_account_type.name if financial_account_type end # Friendly name for account_number_source def account_source I18n.t("financial_accounts.account_number_sources.#{account_number_source}") end def account_source=(friendly_name) number_source = I18n.t('financial_accounts.account_number_sources').select { |k,v| v == friendly_name } self.account_number_source = number_source.blank? ? 'regular' : number_source.keys.first.to_s end def import!(data) FinancialAccount::ImportLogic.new(self, data).process! end def export FinancialAccount::ExportLogic.new(self).process end end